package com.ytjj.qmyx.supplychain.api.controller;

import com.ytjj.qmyx.supplychain.common.api.CommonPage;
import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.common.enums.SmsSignEnum;
import com.ytjj.qmyx.supplychain.common.model.request.SmsTemplateRequest;
import com.ytjj.qmyx.supplychain.mapper.entity.YxSmsTemplate;
import com.ytjj.qmyx.supplychain.service.SmsManageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jiawei
 * @date 2024年06月06日 10:06
 * @describe 短信发送相关接口
 */
@Slf4j
@RestController
@RequestMapping("/smsManage")
public class SmsManageController {

    @Resource
    private SmsManageService smsManageService;

    /**
     * 分页查询模板列表
     */
    @PostMapping("/getTemplateOnePage")
    public CommonResult<CommonPage<YxSmsTemplate>> getTemplateOnePage(@RequestBody SmsTemplateRequest request) {
        return CommonResult.success(smsManageService.getTemplateOnePage(request));
    }

    /**
     * 编辑新增短信模板
     * @param smsTemplate
     * @return
     */
    @PostMapping("/addOrEditTemplate")
    public CommonResult addOrEditTemplate(@RequestBody YxSmsTemplate smsTemplate) {
        return smsManageService.addOrEditTemplate(smsTemplate);
    }

    /**
     * 修改模板状态
     * @param id 模板id
     * @param status 状态 0-禁用 1-启用
     * @return CommonResult<List<String>>
     */
    @GetMapping("/changeStatus")
    public CommonResult<List<String>> changeStatus(Integer id, Integer status) {
        Integer integer = smsManageService.changeStatus(id, status);
        return integer > 0 ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 删除模板
     * @param id 模板id
     * @return CommonResult<List<String>>
     */
    @GetMapping("/delete")
    public CommonResult<List<String>> delete(Integer id) {
        Integer integer = smsManageService.delete(id);
        return integer > 0 ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 获得所有的短信签名
     * @return
     */
    @GetMapping("/getAllSign")
    public CommonResult<List<String>> getAllSign() {
        List<String> allSign = SmsSignEnum.getAllSign();
        return CommonResult.success(allSign);
    }
}
